using Humanizer;

namespace RSCore.Files;
public sealed record class SimpleFile(string Name) : RSFile(Name), IKeyConvertable
{
	public string DisplayName { get; set; } = Name.GetDefaultDisplayName();

	public override void Deserialize(JsonValue json)
	{
		DisplayName = json.GetText(nameof(DisplayName));
	}

	public IEnumerable<KeyValuePair<KeyData, string>> Convert()
	{
		Debug.Assert(Parent != null);
		var entryType = EnumManager<EntryType>.Shared[Parent.Name.Singularize()];
		yield return new(new(Name, entryType, nameof(DisplayName)), DisplayName);
	}

	public override void Load(BinaryReader reader)
	{
		DisplayName = reader.ReadString();
	}

	public override void Save(BinaryWriter writer)
	{
		writer.Write(DisplayName);
	}

	public override JsonValue Serialize()
	{
		return new JsonObject
		{
			{ nameof(DisplayName), DisplayName },
		};
	}

	public override void Write(StreamWriter writer, RSFile? annotation)
	{
		var orig = annotation as SimpleFile;
		writer.WriteProperty(DisplayName, orig?.DisplayName);
	}

	public override void Read(StreamReader reader)
	{
		var properties = reader.ReadProperties();
		DisplayName = properties.GetText(nameof(DisplayName));
	}
}